package cn.vc.communityservice.service;

import cn.vc.communityservice.entity.Community;
import cn.vc.communityservice.mapper.CommunityMapper;
import org.springframework.stereotype.Service;

@Service
public class CommunityService {
    private final CommunityMapper communityMapper;

    public CommunityService(CommunityMapper communityMapper) {
        this.communityMapper = communityMapper;
    }

    public boolean found(Community community) {
        return communityMapper.insert(community)==1;
    }



    public boolean delete(Long id, Long founderId) {
        Community community = communityMapper.selectById(id);
        if (community.getFounderId().equals(founderId)) {
            return communityMapper.deleteById(id)==1;
        } else return false;
    }



    public Community selectById(Long id) {
        return communityMapper.selectById(id);
    }



    public boolean update(Community community) {
        return communityMapper.updateById(community)==1;
    }
}
